package com.neusoft.yuejian_6.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.activity.MasterInfoActivity;
import com.neusoft.yuejian_6.javabean.Master;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.neusoft.yuejian_6.base.Constant.PHOTO_URL;

/**
 * Created by Q on 2017/10/17.
 */

public class MasterListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public MasterListAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Master entity = (Master) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        MasterListAdapter.ViewHolder viewHolder = (MasterListAdapter.ViewHolder) holder;
      //  ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.master_name.setText(entity.getMaster_name());
        viewHolder.master_hot.setText(entity.getMaster_hot()+ "");


        String master_pic =PHOTO_URL+entity.getMaster_pic();

        Picasso.with(mContext).load(master_pic).into(viewHolder.master_pic);
        if(viewHolder.master_pic.getDrawable()==null){
            viewHolder.master_pic.setImageResource(R.drawable.no_pic);
        }
        //点击item跳转
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putInt("master_id",entity.getMaster_id());
                bundle.putString("master_name",entity.getMaster_name());
                bundle.putInt("master_hot",entity.getMaster_hot());
                bundle.putString("master_intro",entity.getMaster_info());
                bundle.putInt("club_id",entity.getClub_id());
                bundle.putString("club_name",entity.getClub_name());
                bundle.putString("master_pic",entity.getMaster_pic());
                bundle.putInt("master_age",entity.getMaster_age());
                bundle.putString("master_sex",entity.getMaster_sex());
                Intent intent=new Intent(mContext, MasterInfoActivity.class);
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //创建ViewHolder
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_quanwei, parent, false);
        return new ViewHolder(v);

    }

    //自定义的V
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView master_pic;
        TextView master_name,master_hot;

        public ViewHolder(View itemView) {
            super(itemView);
            master_name = (TextView) itemView.findViewById(R.id.master_name);
            master_pic = (ImageView) itemView.findViewById(R.id.master_pic);
            master_hot= (TextView) itemView.findViewById(R.id.hot_count);


        }
    }
}

